#define _CRT_SECURE_NO_WARNINGS 1
#include <stdio.h>
int main()
{
    int n, a = 1, j = 2;
    scanf("%d", &n);
    if (n == 3)
    {
        printf("2");
    }
    for (n=n-1; n > 0; n--)
    {
        for (j = 2; j < n; j++)
        {
            if (n % j == 0)
            {
                break;
            }
            else
            {
                if (j == n - 1)
                {
                    printf("%d", n);
                    a = 0;
                    break;
                }
            }
        }
        if (a == 0)
            break;
    }

    return 0;
}